#ifndef FBLIB_H
#define FBLIB_H

#include "Color.h"
#include "Bitmap.h"


//#define PINK RGB16(255,182,193)
//#define PURPLE RGB16(128,0,128)

#define DrawAnd      (0x1<<0)
#define DrawOr       (0x1<<1)
#define DrawCover    (0x1<<2)
#define DrawInvertX  (0x1<<3)
#define DrawInvertY  (0x1<<4)

#include <linux/fb.h>

typedef struct Rect {
    int x;
    int y;
    int width;
    int height;
} Rect;

//#pragma pack(4)
typedef struct fb_dev {
    int fd;
    struct fb_fix_screeninfo fb_fix_screeninfo;
    struct fb_var_screeninfo fb_var_screeninfo;
    int bits_per_pixel;
    int xres;
    int yres;
    int buffer_size;
    int mask;
    char* start_buffer;
    char* double_buffer;
} fb_dev;

struct fb_dev* fb_open(char* const devname, int mode);
void fb_close(struct fb_dev* dev);
void fb_info(struct fb_dev* const dev);
long start_location(struct fb_dev* const dev, int x, int y);

void fb_draw_pixel(struct fb_dev* const dev, int x, int y, int color);
void fb_draw_line(struct fb_dev* const dev, int x1, int y1, int x2, int y2, int color);
void fb_draw_rect(struct fb_dev* const dev, int x, int y, int width, int height, int color);
void fb_fill_rect(struct fb_dev* const dev, int x, int y, int width, int height, int color);
void fb_draw_circle(struct fb_dev* const dev, int x, int y, int radius, int color);
void fb_fill_circle(struct fb_dev* const dev, int x, int y, int radius, int color);
//void fb_draw_bitmap(struct fb_dev* const dev, int x, int y, int bitmap);

// convert color into another form
// like 16 bits to 24 bits...
// *to save converted data, from is the origin color data, 
void fb_convert_color(char* to, int to_size, char* from, int from_size);

void fb_draw_bitmap(struct fb_dev* const dev, Rect des_rect, Rect res_rect, 
	const Bitmap* bitmap, int draw_way);

void fb_repaint(struct fb_dev* const dev, int x, int y, int width, int height);
void fb_repaint_all(struct fb_dev* const dev);
#endif //FBLIB_H
